package com.hnevc.androiduiclassone4;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

/**
 * Created by Administrator on 2018/6/6.
 */

public class MyDialog extends Dialog {
    EditText editText;
    Context context;
    public MyDialog(@NonNull Context context) {
        super(context);
        this.context=context;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout);//绑定布局文件
        editText=findViewById(R.id.et_name);//获取控件

        Button btnok =findViewById(R.id.btn_ok);
        Button btno =findViewById(R.id.btn_cancel);
        btnok.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(context, editText.getText().toString(), Toast.LENGTH_SHORT).show();
                dismiss();//  关闭对话框
            }
        });
    }
}
